home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / hsrc_117.zip / MODERATE.C < prev    next >
Text File  |  1990-11-24  |  14KB  |  490 lines

  1. #include "msgg.h"
  2. #include "twindow.h"
  3. #include "keys.h"
  4. #include "headedit.h"
  5.  
  6.     struct tracker {
  7.         char *str;
  8.         word x;
  9.         struct tracker *next;
  10.     };
  11.  
  12. extern WINDOW *ewnd;
  13.  
  14. extern char pascal ask_question(char *);
  15. struct tracker * pascal sort_tracker (struct tracker *);
  16. void pascal free_trackers(struct tracker *);
  17.  
  18.  
  19.  
  20. void pascal do_breakdown (void) {
  21.  
  22.     WINDOW *wnd;
  23.     char *hold,*tempo,*p;
  24.     char appendto=0;
  25.     struct ffblk f;
  26.     char fname[81];
  27.     char m[81];
  28.     word from,to,tempmessno,percent;
  29.     struct tracker *froms,*tos,*subjs,*origins,*tf,*tt,*ts,*too,*ttt;
  30.     int prnthandle=0;
  31.     long total,counter,scanned;
  32.  
  33.     froms=tos=subjs=origins=tf=tt=ts=too=NULL;
  34.     sprintf(m,"%01u",messno);
  35.     from=(word)atol(get_string(" Start at which #:",5,m,'N'));
  36.     if(from<1 || from>nomess) return;
  37.     sprintf(m,"%01u",nomess);
  38.     to=(word)atol(get_string(" End at which #:",5,m,'N'));
  39.     if(to<from) to=nomess;
  40.     sprintf(m,"ECHOBDN.%03x",currarea->number);
  41.     strcpy(fname,get_string(" Export filename: ",78,m,'A'));
  42.     if(!findfirst(fname,&f,0)) {
  43.         sprintf(m," %1.55s exists...overwrite? (Y/n)",fname);
  44.         tempmessno=ask_question(m);
  45.         if(tempmessno=='N' || tempmessno==ESC) appendto=1;
  46.         set_help("",0,0);
  47.     }
  48.     tempmessno=messno;
  49.  
  50.     _anymsg(" Working... ","                    ");
  51.     scanned=0L;
  52.     for(messno=from;messno<(to+1);messno++) {
  53.         wcursor(ewnd,0,0);
  54.         wprintf(ewnd," %01u  %01lu",messno,farcoreleft());
  55.         get_mess(0);
  56.         if(msg.m_attr & MSGDELETED) continue;
  57.         scanned++;
  58.         if((currarea->attr & ECHO) || (currarea->attr & ALTECHO)) {
  59.           hold=get_text();
  60.           if(hold) {
  61.             tempo=strstr(hold,"\r * Origin: ");
  62.             if(!tempo)tempo=strstr(hold,"\n * Origin: ");
  63.             if(tempo) {
  64.                 tempo+=12;
  65.                 p=strchr(tempo,'\r');
  66.                 if(p) *p=0;
  67.                 tempo=strrchr(tempo,'(');
  68.                 if(!tempo) goto SkipOrigins;
  69.                 tempo++;
  70.                 p=strchr(tempo,')');
  71.                 if(p)*p=0;
  72.                 rstrip(tempo);
  73.                 p=lstrip(tempo);
  74.                 while(*p!=' ' && *p)p++;
  75.                 if(*p==' ') {
  76.                     while(*p==' ')p++;
  77.                     tempo=p;
  78.                 }
  79.                 if(!tempo || !*tempo) goto SkipOrigins;
  80.                 if(origins) {
  81.                     ttt=origins;
  82.                     while(ttt) {
  83.                         if(!stricmp(ttt->str,tempo)) {
  84.                             ttt->x++;
  85.                             goto SkipOrigins;
  86.                         }
  87.                         ttt=ttt->next;
  88.                     }
  89.                 }
  90.                 ttt=(struct tracker *)malloc(sizeof(struct tracker));
  91.                 if(!ttt) {
  92.  
  93.                 }
  94.                 else {
  95.                     ttt->str=strdup(tempo);
  96.                     ttt->x=1;
  97.                     ttt->next=NULL;
  98.                     if(!origins) {
  99.                         origins=ttt;
  100.                         too=origins;
  101.                     }
  102.                     else {
  103.                         too->next=ttt;
  104.                         too=ttt;
  105.                     }
  106.                 }
  107.             }
  108. SkipOrigins:
  109.             if(hold)farfree(hold);
  110.           }
  111.         }
  112.         if(froms) {
  113.             ttt=froms;
  114.             while(ttt) {
  115.                 if(!stricmp(ttt->str,msg.from)) {
  116.                     ttt->x++;
  117.                     goto SkipFroms;
  118.                 }
  119.                 ttt=ttt->next;
  120.             }
  121.         }
  122.         ttt=(struct tracker *)malloc(sizeof(struct tracker));
  123.         if(!ttt) {
  124.  
  125.         }
  126.         else {
  127.             ttt->str=strdup(lstrip(rstrip(msg.from)));
  128.             ttt->x=1;
  129.             ttt->next=NULL;
  130.             if(!froms) {
  131.                 froms=ttt;
  132.                 tf=froms;
  133.             }
  134.             else {
  135.                 tf->next=ttt;
  136.                 tf=ttt;
  137.             }
  138.         }
  139. SkipFroms:
  140.         if(tos) {
  141.             ttt=tos;
  142.             while(ttt) {
  143.                 if(!stricmp(ttt->str,msg.to)) {
  144.                     ttt->x++;
  145.                     goto SkipTos;
  146.                 }
  147.                 ttt=ttt->next;
  148.             }
  149.         }
  150.         ttt=(struct tracker *)malloc(sizeof(struct tracker));
  151.         if(!ttt) {
  152.  
  153.         }
  154.         else {
  155.             ttt->str=strdup(lstrip(rstrip(msg.to)));
  156.             ttt->x=1;
  157.             ttt->next=NULL;
  158.             if(!tos) {
  159.                 tos=ttt;
  160.                 tt=tos;
  161.             }
  162.             else {
  163.                 tt->next=ttt;
  164.                 tt=ttt;
  165.             }
  166.         }
  167. SkipTos:
  168.         if(subjs) {
  169.             ttt=subjs;
  170.             while(ttt) {
  171.                 p=msg.subj;
  172.                 while(*p==' ')p++;
  173.                 if(!strnicmp(p,"RE:",3)) {
  174.                     p+=3;
  175.                     while(*p==' ')p++;
  176.                 }
  177.                 if(!stricmp(ttt->str,p)) {
  178.                     ttt->x++;
  179.                     goto SkipSubjs;
  180.                 }
  181.                 ttt=ttt->next;
  182.             }
  183.         }
  184.         ttt=(struct tracker *)malloc(sizeof(struct tracker));
  185.         if(!ttt) {
  186.  
  187.         }
  188.         else {
  189.             p=msg.subj;
  190.             while(*p==' ')p++;
  191.             if(!strnicmp(p,"RE:",3)) {
  192.                 p+=3;
  193.                 while(*p==' ')p++;
  194.             }
  195.             ttt->str=strdup(lstrip(rstrip(p)));
  196.             ttt->x=1;
  197.             ttt->next=NULL;
  198.             if(!subjs) {
  199.                 subjs=ttt;
  200.                 ts=subjs;
  201.             }
  202.             else {
  203.                 ts->next=ttt;
  204.                 ts=ttt;
  205.             }
  206.         }
  207. SkipSubjs:
  208. ;
  209.     }
  210.  
  211.     wprintf(ewnd,"\n Sorting ");
  212.     if(froms) froms=sort_tracker(froms);
  213.     if(tos) tos=sort_tracker(tos);
  214.     if(subjs) subjs=sort_tracker(subjs);
  215.     if(origins) origins=sort_tracker(origins);
  216.  
  217.     clear_message();
  218.     wnd=establish_window(7,5,maxy-5,80);
  219.     set_title(wnd," Msg area breakdown ");
  220.     set_colors(wnd,ALL,BLACK,WHITE,BRIGHT);
  221.     set_colors(wnd,ACCENT,WHITE,BLACK,BRIGHT);
  222.     set_colors(wnd,BORDER,BLACK,AQUA,DIM);
  223.     set_colors(wnd,TITLE,BLACK,AQUA,BRIGHT);
  224.     display_window(wnd);
  225.     wcursor(wnd,0,0);
  226.  
  227.     if(!stricmp(fname,"PRN")) {
  228.         _AH=2;
  229.         _DX=0;
  230.         geninterrupt(0x17);
  231.         if (_AH!=144) {
  232.             error_message(" Printer not ready ");
  233.             pause();
  234.             _AH=2;
  235.             _DX=0;
  236.             geninterrupt(0x17);
  237.             if(_AH!=144) prnthandle = -1;
  238.         }
  239.     }
  240.     if(!prnthandle && *fname) {
  241.         if(!appendto)unlink(fname);
  242.         prnthandle=_open(fname,O_WRONLY | O_BINARY | O_DENYWRITE);
  243.         if(prnthandle== -1) prnthandle=creat(fname,S_IWRITE);
  244.     }
  245.  
  246.     if(prnthandle!= -1) {
  247.         if(stricmp(fname,"PRN") && appendto) lseek(prnthandle,0L,SEEK_END);
  248.         ffprintf(prnthandle,"\r\n\r\n Date:  %s\r\n",fidodate());
  249.         ffprintf(prnthandle,"\r\n Summary of echo area #%u  \"%s\":\r\n Scanned %lu msgs\r\n\r\n",currarea->number,currarea->name,scanned);
  250.     }
  251.     else prnthandle= -1;
  252.     wprintf(wnd,"Summary of echo area #%u  \"%s\":\nScanned %lu msgs\n\n",currarea->number,currarea->name,scanned);
  253.  
  254.     if(froms) {
  255.         counter=total=0L;
  256.         if(prnthandle!= -1) {
  257.             ffprintf(prnthandle,"Author                                 #posts\r\n");
  258.             ffprintf(prnthandle,"=============================================\r\n");
  259.         }
  260.         wprintf(wnd,"Author                                 #posts\n");
  261.         wprintf(wnd,"=============================================\n");
  262.         tt=froms;
  263.         while(tt) {
  264.           if(tt->str) {
  265.             if(prnthandle!= -1) {
  266.                 ffprintf(prnthandle,"%-40.40s%5u",tt->str,tt->x);
  267.             }
  268.             wprintf(wnd,"%-40.40s%5u",tt->str,tt->x);
  269.             percent=(word)(((long)tt->x * 100L) / scanned);
  270.             if(percent) {
  271.                 if(prnthandle!= -1) {
  272.                     ffprintf(prnthandle,"  (%u%%)",percent);
  273.                 }
  274.                 wprintf(wnd,"  (%u%%)",percent);
  275.             }
  276.             if(prnthandle != -1) {
  277.                 ffprintf(prnthandle,"\r\n");
  278.             }
  279.             wprintf(wnd,"\n");
  280.             total+=(long)tt->x;
  281.             counter++;
  282.           }
  283.           tt=tt->next;
  284.         }
  285.         if(prnthandle!= -1) {
  286.             ffprintf(prnthandle,"=============================================\r\n");
  287.             ffprintf(prnthandle,"Totals:  %5lu                          %5lu\r\n\r\n",counter,total);
  288.         }
  289.         wprintf(wnd,"=============================================\n");
  290.         wprintf(wnd,"Totals:  %5lu